package com.betterwood.dragon.dao.enhances.impl;

import com.betterwood.dragon.dao.common.MongoDBUtils;
import com.betterwood.dragon.dao.enhances.UserMongoRepository;
import com.betterwood.dragon.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import java.lang.reflect.InvocationTargetException;

/**
 * @author zhengyanhua
 * @create 2021-03-18 13:59
 */
public class UserMongoRepositoryImpl implements UserMongoRepository {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void updateUser(User record) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        Query query= MongoDBUtils.getQuery(record.getId());
        Update update= MongoDBUtils.getUpdate(record);
        mongoTemplate.updateFirst(query,update, User.class);
    }
}
